<?php
    include 'config.php';
    date_default_timezone_set("Asia/Shanghai");
    if($_POST){
        try{
         $dbh = dbConnect();
         $sql = "insert into diary(title,content,addtime) value
             ('".$_POST['title']."',
             '".$_POST['content']."',
             '".date("Y-m-d H:i:s")."')";
         $sth = $dbh->query($sql);
         if($sth){
             header("Location:index.php");
         }
        }catch(PDOException $e){
            print('Error'.$e->getMessage());
            die();
        }        
     }
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>write</title>
    <link rel="stylesheet" href="./css/common.css">
</head>
<body class="common-body">
    <div class="common-form-wrap">
        <form action="write.php" method="POST">
            <table class="common-table">
                <tr>
                    <th colspan="2"><span style="font-size: 30px;color:white;">伝言を入力してください</span></th>
                </tr>
                <tr>
                    <td>TITLE</td>
                    <td><input type="text" name="title"></td>
                </tr>
                <tr>
                    <td>CONTENT</td>
                    <td><textarea name="content" id="" cols="30" rows="10"></textarea></td>
                </tr>
                <tr>
                    <td>ADDTIME</td>
                    <td><input type="text" readonly value="<?= date('Y-m-d H:i:s')?>"></td>
                </tr>
                <tr class="common-footer-button">
                    <td colspan="2"><input type="submit" value="提出"></td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>